package servlets;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import domain.Contact;
import domain.IDAOContact;

public class showContactsLinkAction extends Action {

	public ActionForward execute(final ActionMapping pMapping, ActionForm pForm, final HttpServletRequest pRequest, final HttpServletResponse pResponse) {
		ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(pRequest.getSession().getServletContext());
		IDAOContact dao = (IDAOContact)context.getBean("daoContact");	
		String type = (String) pRequest.getParameter("type");
		pRequest.setAttribute("type", type);
		List<Contact> contacts = dao.getAllContact();
		pRequest.setAttribute("contacts", contacts);
		return pMapping.findForward("showContactsLinkPage");
	}
}